fix fromOsPath on windows
authorJoey Hess <joeyh@joeyh.name>
Wed, 29 Jan 2025 18:19:25 +0000 (14:19 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 29 Jan 2025 18:19:25 +0000 (14:19 -0400)
Same reasons as 9c9baf7c6581235643661b94f70f76f8a10ae60e

Utility/OsPath.hs

index bd7baf85eb3c82c9f717bf732d8c71ec32626ae4..9fa4e0f57e57088a9e509112089eec13ec34005f 100644 (file)
@@ -24,6 +24,8 @@ import "os-string" System.OsString.Internal.Types
 import qualified Data.ByteString.Short as S
 #if defined(mingw32_HOST_OS)
 import GHC.IO (unsafePerformIO)
+import System.OsString.Encoding.Internal (cWcharsToChars_UCS2)
+import qualified System.OsString.Data.ByteString.Short.Word16 as BS16
 #endif
 
 toOsPath :: RawFilePath -> OsPath
@@ -38,7 +40,10 @@ toOsPath = OsString . PosixString . S.toShort
 
 fromOsPath :: OsPath -> RawFilePath
 #if defined(mingw32_HOST_OS)
-fromOsPath = S.fromShort . getWindowsString . getOsString
+-- On Windows, OsString contains a ShortByteString that is
+-- utf-16 encoded. So have to convert the input from that.
+-- This is relatively expensive.
+fromOsPath = toRawFilePath . cWcharsToChars_UCS2 . BS16.unpack . getWindowsString
 #else
 fromOsPath = S.fromShort . getPosixString . getOsString
 #endif